package cn.jarlen.jwt.tools.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.example.jarlen.myapplication.R;
import cn.jarlen.jwt.tools.menu.MenuBean;

import java.util.Random;

/**
 * @author jarlen
 * Create by 2023/4/12 13:14
 */
public class MenuAdapter extends RvCommonAdapter<MenuBean> {

    private OnMenuItemClickListener onMenuItemClickListener;

    public void setOnMenuItemClickListener(OnMenuItemClickListener onMenuItemClickListener) {
        this.onMenuItemClickListener = onMenuItemClickListener;
    }

    public MenuAdapter(Context context) {
        super(context);
    }

    @Override
    public void onBindView(RvViewHolder viewHolder, MenuBean item) {
        TextView menuName = viewHolder.getView(R.id.tv_menu_name);
        menuName.setText(item.getMenuName());
        viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onMenuItemClickListener == null) {
                    return;
                }
                onMenuItemClickListener.onMenuItemClick(item);
            }
        });

        Random read = new Random();
        int red = read.nextInt(255);
        int green = read.nextInt(255);
        int blue = read.nextInt(255);

        viewHolder.getConvertView().setBackgroundColor(Color.argb(255, red, green, blue));
    }

    @Override
    public int getLayoutResId(int viewType) {
        return R.layout.layout_menu_item;
    }

    public interface OnMenuItemClickListener {
        void onMenuItemClick(MenuBean menuBean);
    }
}
